//
//  QZHomePlayCell.m
//  shortvideoplay
//
//  Created by adam on 2024/6/13.
//

#import "QZHomePlayCell.h"
#import "JPVideoPlayerKit.h"
#import <AVFoundation/AVFoundation.h>
#import "BVideoCacheTool.h"
#import "SJProgressSlider.h"
#import "QZVideoPlaySliderView.h"
#import "DJJubaoVC.h"
#import "CommentsPopView.h"
#import "SharePopView.h"
#import "UIImage+Compression.h"
#import "ZFSliderView.h"
#import "NSAttributedString+YYText.h"
#import "DJMYBIVC.h"
#import "YBNetworking.h"

static const NSInteger kAwemeListLikeCommentTag = 0x01;
static const NSInteger kAwemeListLikeShareTag   = 0x02;
static const NSInteger kAwemeListLikeCollectionTag   = 0x03;
static const NSInteger kAwemeListLikeHuaTag   = 0x04;

@interface QZHomePlayCell ()<JPVideoPlayerDelegate,UIGestureRecognizerDelegate,SendTextDelegate, HoverTextViewDelegate, AVPlayerUpdateDelegate,SharePopViewDelegate,ZFSliderViewDelegate>

@property (nonatomic,assign) BVideoCacheResult playCacheResult;//判断是否是缓存

@property (strong, nonatomic) QZVideoPlaySliderView * slider;
@property (strong, nonatomic)  UILabel *home_recommend_title;//标题
@property (strong, nonatomic)  UILabel *home_recommend_subTitle;//子标题

/*第二版本*/

@property (nonatomic, strong) UIView                   *container;
@property (nonatomic ,strong) CAGradientLayer          *gradientLayer1;
@property (nonatomic ,strong) CAGradientLayer          *gradientLayer2;
@property (nonatomic ,strong) UIImageView              *pauseIcon;
@property (nonatomic, strong) UIView                   *playerStatusBar;
//@property (nonatomic ,strong) UIImageView              *musicIcon;
@property (nonatomic, strong) UITapGestureRecognizer   *singleTapGesture;
@property (nonatomic, assign) NSTimeInterval           lastTapTime;
@property (nonatomic, assign) CGPoint                  lastTapPoint;

@property (nonatomic, assign) CGFloat                  cellHeight;
@property (nonatomic, assign) BOOL                  isTouch;

@property (nonatomic, strong) UIView * effectBg;

@property (nonatomic, assign) BOOL                  isEndLoading;
@end
@implementation QZHomePlayCell

- (void)showOldAddNavViewToMainOldView1{
    UIView * oldBgSS = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    oldBgSS.clipsToBounds = YES;
    [self addSubview:oldBgSS];
    
    UIButton * sendBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreen_W-75, kStatusBarHeight+10, 60, 46)];
    sendBtn.layer.cornerRadius = 3;
    sendBtn.backgroundColor = [UIColor whiteColor];
    [sendBtn setTitle:@"发送" forState:UIControlStateNormal];
    [sendBtn setTitleColor:ColorHex(@"#333333") forState:UIControlStateNormal];
    sendBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [sendBtn addTarget:self action:@selector(sendTap) forControlEvents:UIControlEventTouchUpInside];
    [oldBgSS addSubview:sendBtn];
    
    UIView * sendBg = [[UIView alloc]initWithFrame:CGRectMake(15, kStatusBarHeight+66, KScreen_W-30, (KScreen_H-KSafeAreaBottomHeight-25-(kStatusBarHeight+66))/2)];
    sendBg.backgroundColor = [UIColor whiteColor];
    sendBg.layer.cornerRadius = 3;
    [oldBgSS addSubview:sendBg];
    
    UILabel * sendTip = [[UILabel alloc]initWithFrame:CGRectMake(0, (sendBg.frame.size.height-40)/2, sendBg.frame.size.width, 40)];
    sendTip.text = @"发送区";
    sendTip.textColor = ColorHex(@"#f0f0f0");
    sendTip.textAlignment = NSTextAlignmentCenter;
    sendTip.font = [UIFont systemFontOfSize:28];
    [sendBg addSubview:sendTip];
}
- (void)awakeFromNib {
    [super awakeFromNib];
    UIImageView * showTextViewImgTo2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 60, 60)];
    showTextViewImgTo2.hidden = YES;
    showTextViewImgTo2.layer.cornerRadius = K_AUTOLAYOUT_W(30);
    showTextViewImgTo2.clipsToBounds = YES;
    showTextViewImgTo2.contentMode = UIViewContentModeScaleAspectFill;
    [self addSubview:showTextViewImgTo2];
    
    UILabel * showTextViewLabelTo2 = [[UILabel alloc]initWithFrame:CGRectMake(15, 35, KScreen_W-30, 30)];
    showTextViewLabelTo2.hidden = YES;
    showTextViewLabelTo2.font = FontBold(18);
    showTextViewLabelTo2.textColor = ThreeColor;
    showTextViewLabelTo2.textAlignment = NSTextAlignmentCenter;
    [self addSubview:showTextViewLabelTo2];
    // Initialization code
}
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if(self) {
        self.backgroundColor = viewback_black;
        self.cellHeight = frame.size.height;
        _lastTapTime = 0;
        _lastTapPoint = CGPointZero;
        [self initSubViews];
        self.clipsToBounds = YES;
    UIButton * textShowButtonTo1 = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        NSString * textShowButtonTitleTo1 = @"测试功能";
        [textShowButtonTo1 setTitle:textShowButtonTitleTo1 forState:UIControlStateNormal];
        NSInteger textShowArcTo1 = arc4random_uniform(22);
        NSLog(@"随机数：%ld", (long)textShowArcTo1);
    }
    return self;
}

- (void)initSubViews {
    //init player view;
    self.hoem_recommend_playview = [[UIView alloc]init];
    self.hoem_recommend_playview.backgroundColor = [UIColor clearColor];
    [self addSubview:self.hoem_recommend_playview];

    self.hoem_recommend_imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, KScreen_W, KScreen_H-KTab_H)];
    self.hoem_recommend_imageView.contentMode = UIViewContentModeScaleAspectFill;
    self.hoem_recommend_imageView.clipsToBounds = YES;
    self.hoem_recommend_imageView.backgroundColor = [UIColor clearColor];
    [self addSubview:self.hoem_recommend_imageView];

    
    //init hover on player view container
    _container = [UIView new];
    [self.contentView addSubview:_container];
    
    _singleTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
    _singleTapGesture.cancelsTouchesInView = NO;
    [_container addGestureRecognizer:_singleTapGesture];
    
    _gradientLayer1 = [CAGradientLayer layer];
    _gradientLayer1.colors = @[(__bridge id)COLOR_ALPH(0.0, 0.0, 0.0, 0.5).CGColor, (__bridge id)COLOR_ALPH(0.0, 0.0, 0.0, 0.25).CGColor,(__bridge id)[UIColor clearColor].CGColor];
    _gradientLayer1.locations = @[@0.3, @0.6, @1.0];
    _gradientLayer1.startPoint = CGPointMake(0.0f, 0.0f);
    _gradientLayer1.endPoint = CGPointMake(0.0f, 1.0f);
    [_container.layer addSublayer:_gradientLayer1];
    
    _gradientLayer2 = [CAGradientLayer layer];
    _gradientLayer2.colors = @[(__bridge id)[UIColor clearColor].CGColor, (__bridge id)COLOR_ALPH(0.0, 0.0, 0.0, 0.35).CGColor, (__bridge id)COLOR_ALPH(0.0, 0.0, 0.0, 0.7).CGColor];
    _gradientLayer2.locations = @[@0.3, @0.6, @1.0];
    _gradientLayer2.startPoint = CGPointMake(0.0f, 0.0f);
    _gradientLayer2.endPoint = CGPointMake(0.0f, 1.0f);
    [_container.layer addSublayer:_gradientLayer2];
    
    _pauseIcon = [[UIImageView alloc] init];
    _pauseIcon.image = [UIImage imageNamed:@"pause"];
    _pauseIcon.contentMode = UIViewContentModeCenter;
    _pauseIcon.layer.zPosition = 3;
    _pauseIcon.hidden = YES;
    [_container addSubview:_pauseIcon];
    

    
    _inputView = [[UIButton alloc]init];
    [_inputView setTitle:@"    有爱评论，说点儿好听的~" forState:UIControlStateNormal];
    [_inputView setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _inputView.titleLabel.font = Font(15);
    [_inputView addTarget:self action:@selector(commentTap) forControlEvents:UIControlEventTouchUpInside];
    _inputView.backgroundColor = subviewback_black;
    _inputView.layer.cornerRadius = 12;
    _inputView.clipsToBounds = YES;
    _inputView.hidden = YES;
    [_container addSubview:_inputView];
    
    _sliderView = [[ZFSliderView alloc]init];
    _sliderView.backgroundColor = [UIColor clearColor];
    _sliderView.maximumTrackTintColor = ColorHex_Alpha(@"FFFFFF", 0.46);//UIColor.clearColor;
    _sliderView.minimumTrackTintColor = ColorHex_Alpha(@"FFFFFF", 1);
    _sliderView.delegate = self;
    _sliderView.sliderHeight = 2;
    _sliderView.hidden = YES;
    [_container addSubview:_sliderView];
    
    
    //init player status bar
    _playerStatusBar = [[UIView alloc]init];
    [_playerStatusBar setHidden:YES];
    [_container addSubview:_playerStatusBar];
    
    //init aweme message
//    _musicIcon = [[UIImageView alloc]init];
//    _musicIcon.contentMode = UIViewContentModeCenter;
//    _musicIcon.image = [UIImage imageNamed:@"douyin"];
//    [_container addSubview:_musicIcon];
    
//    _musicName = [[CircleTextView alloc]init];
//    _musicName.textColor = [UIColor whiteColor];
//    _musicName.font = Font(14);
//    [_container addSubview:_musicName];
    
    KWeakSelf
    _desc = [[YYLabel alloc]init];
    _desc.numberOfLines = 0;
    _desc.textColor = COLOR_ALPH(255.0, 255.0, 255.0, 0.8);
    _desc.font = Font(14);
    _desc.userInteractionEnabled = YES;
    _desc.tag = 102;
    [_container addSubview:_desc];
    NSMutableAttributedString * moreAttr = [[NSMutableAttributedString alloc] initWithString:@"... 展开" attributes:@{NSForegroundColorAttributeName : [UIColor whiteColor], NSFontAttributeName : FontMedium(14)}];

    [moreAttr setTextHighlightRange:NSMakeRange(0, moreAttr.length) color:UIColor.whiteColor backgroundColor:UIColor.clearColor tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        //点击
        weakSelf.videoModel.isOpenIntro = YES;
        NSMutableAttributedString * moreAttr = [[NSMutableAttributedString alloc] initWithString:weakSelf.videoModel.introduce attributes:@{NSForegroundColorAttributeName : [UIColor whiteColor], NSFontAttributeName : Font(14)}];
        NSMutableAttributedString * closeAttr = [[NSMutableAttributedString alloc] initWithString:@".... 收起" attributes:@{NSForegroundColorAttributeName : [UIColor whiteColor], NSFontAttributeName : FontMedium(14)}];
        [closeAttr setTextHighlightRange:NSMakeRange(0, closeAttr.length) color:[UIColor whiteColor] backgroundColor:UIColor.clearColor tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
            //点击
            weakSelf.videoModel.isOpenIntro = NO;
            
            NSMutableAttributedString * moreAttr = [[NSMutableAttributedString alloc] initWithString:weakSelf.videoModel.introduce attributes:@{NSForegroundColorAttributeName : [UIColor whiteColor], NSFontAttributeName : Font(14)}];
            weakSelf.desc.numberOfLines = 2;
            weakSelf.videoModel.introHeight = [moreAttr boundingRectWithSize:CGSizeMake(KScreen_W/5*3, weakSelf.desc.font.lineHeight*2) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading context:nil].size.height+2;
            [weakSelf updateVideoTalks:moreAttr];
            weakSelf.desc.attributedText = moreAttr;
            [weakSelf.desc mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo (weakSelf.videoModel.introHeight);
            }];
        }];
        [moreAttr appendAttributedString:closeAttr];
        [weakSelf updateVideoTalks:moreAttr];
        weakSelf.desc.attributedText = moreAttr;
        weakSelf.desc.numberOfLines = 0;
        weakSelf.videoModel.introHeight = [moreAttr boundingRectWithSize:CGSizeMake(KScreen_W/5*3, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading context:nil].size.height;
        [weakSelf.desc mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo (weakSelf.videoModel.introHeight);
        }];
    }];
    
    YYLabel *moreLabel = [YYLabel new];
    moreLabel.backgroundColor = UIColor.clearColor;
    moreLabel.attributedText = moreAttr;
    [moreLabel sizeToFit];
    NSAttributedString * truncationToken = [NSAttributedString attachmentStringWithContent:moreLabel contentMode:UIViewContentModeScaleAspectFit attachmentSize:moreLabel.frame.size alignToFont:Font(14) alignment:YYTextVerticalAlignmentCenter];
    _desc.truncationToken = truncationToken;
    
    
    _nickName = [[UILabel alloc]init];
    _nickName.textColor = [UIColor whiteColor];
    _nickName.font = Font(16);
    [_container addSubview:_nickName];
    
    _showMoneyView = [[UIView alloc]init];
    _showMoneyView.backgroundColor = [UIColor clearColor];
    [_container addSubview:_showMoneyView];
    
    _showMoneyBgImge = [[UIImageView alloc]init];
    _showMoneyBgImge.backgroundColor = [UIColor clearColor];
    _showMoneyBgImge.alpha = 0.68;
    [_showMoneyView addSubview:_showMoneyBgImge];
    
    _showMoneyLabel = [[UILabel alloc]init];
    _showMoneyLabel.backgroundColor = [UIColor clearColor];
    _showMoneyLabel.textColor = UIColor.whiteColor;
    _showMoneyLabel.textAlignment = NSTextAlignmentCenter;
    _showMoneyLabel.font = FontMedium(14);
    [_showMoneyView addSubview:_showMoneyLabel];
    
    _showMoneyButt = [[UIButton alloc]init];
    _showMoneyButt.backgroundColor = [UIColor clearColor];
    [_showMoneyView addSubview:_showMoneyButt];
    
    
    _ADPlayView = [[UIView alloc]init];
    _ADPlayView.backgroundColor = viewback_black;
    [_container addSubview:_ADPlayView];
    

    
//    //init music alum view
//    _musicAlum = [MusicAlbumView new];
//    [_container addSubview:_musicAlum];
    
    //init share、comment、like action view
    _share = [[UIImageView alloc]init];
    _share.contentMode = UIViewContentModeCenter;
    _share.image = [UIImage imageNamed:@"share"];
    _share.userInteractionEnabled = YES;
    _share.tag = kAwemeListLikeShareTag;
    [_share addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)]];
    [_container addSubview:_share];
    
    _shareNum = [[UILabel alloc]init];
    _shareNum.text = @"0";
    _shareNum.textColor = [UIColor whiteColor];
    _shareNum.font = Font(12);
    [_container addSubview:_shareNum];
    
    _hua = [[UIImageView alloc]init];
    _hua.contentMode = UIViewContentModeCenter;
    _hua.image = [UIImage imageNamed:@"share"];
    _hua.userInteractionEnabled = YES;
    _hua.tag = kAwemeListLikeHuaTag;
    [_hua addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)]];
    [_container addSubview:_hua];
    
    _huaNum = [[UILabel alloc]init];
    _huaNum.text = @"送花";
    _huaNum.textColor = [UIColor whiteColor];
    _huaNum.font = Font(12);
    [_container addSubview:_huaNum];
    
    _collectionNum = [[UILabel alloc]init];
    _collectionNum.text = @"0";
    _collectionNum.textColor = [UIColor whiteColor];
    _collectionNum.font = Font(12);
    [_container addSubview:_collectionNum];
    
    _collection = [[UIImageView alloc]init];
    _collection.contentMode = UIViewContentModeCenter;
    _collection.image = [UIImage imageNamed:@"home_video_collection_nor"];
    _collection.userInteractionEnabled = YES;
    _collection.tag = kAwemeListLikeCollectionTag;
    [_collection addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)]];
    [_container addSubview:_collection];
    
    _comment = [[UIImageView alloc]init];
    _comment.contentMode = UIViewContentModeCenter;
    _comment.image = [UIImage imageNamed:@"comment"];
    _comment.userInteractionEnabled = YES;
    _comment.tag = kAwemeListLikeCommentTag;
    [_comment addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)]];
    [_container addSubview:_comment];
    
    _commentNum = [[UILabel alloc]init];
    _commentNum.text = @"0";
    _commentNum.textColor = [UIColor whiteColor];
    _commentNum.font = Font(12);
    [_container addSubview:_commentNum];
    
    _favorite = [FavoriteView new];
    [_container addSubview:_favorite];
    
    _favoriteNum = [[UILabel alloc]init];
    _favoriteNum.text = @"0";
    _favoriteNum.textColor = [UIColor whiteColor];
    _favoriteNum.font = Font(12);
    [_container addSubview:_favoriteNum];
    
    //init avatar
    CGFloat avatarRadius = 25;
    _avatar = [[UIImageView alloc] init];
    _avatar.image = [UIImage imageNamed:@"ic_head_defuls"];
    _avatar.contentMode = UIViewContentModeScaleToFill;
    _avatar.layer.cornerRadius = avatarRadius;
    _avatar.layer.borderColor = COLOR_ALPH(255.0, 255.0, 255.0, 0.8).CGColor;
    _avatar.layer.borderWidth = 1;
    _avatar.clipsToBounds = YES;
    [_container addSubview:_avatar];
    
    //init focus action
    _focus = [FocusView new];
    [_container addSubview:_focus];
    
    _effectBg = [[UIView alloc]init];
    _effectBg.backgroundColor = UIColor.clearColor;
    [_container addSubview:_effectBg];
    _effectBg.hidden = YES;
    
    UIVisualEffectView * effectView = [[UIVisualEffectView alloc]initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
    effectView.alpha = 0.99;
    [_effectBg addSubview:effectView];
    
    UIImageView * effectImage = [[UIImageView alloc]init];
    effectImage.image = KImageNamed(@"ico_pay_suo");
    [_effectBg addSubview:effectImage];
    
    UILabel * effectTip = [[UILabel alloc]init];
    effectTip.text = @"付费视频，购买会才能观看";
    effectTip.textAlignment = NSTextAlignmentCenter;
    effectTip.font = FontMedium(20);
    effectTip.textColor = NineColor;
    [_effectBg addSubview:effectTip];
    
    
    UIButton * buy = [[UIButton alloc]init];
    buy.backgroundColor = MainColor;
    [buy setTitle:@"购买视频" forState:UIControlStateNormal];
    [buy setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    buy.titleLabel.font = FontBold(15);
    buy.layer.cornerRadius = 12;
    buy.clipsToBounds = YES;
    [buy addTarget:self action:@selector(buyVideoTap) forControlEvents:UIControlEventTouchUpInside];
    [_effectBg addSubview:buy];
    
    [_effectBg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_offset(0);
    }];
    [effectView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_offset(0);
    }];
    
    [effectImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf.effectBg).mas_offset(-60);
        make.centerX.equalTo(weakSelf.effectBg);
        make.width.height.mas_equalTo(80);
    }];
    [effectTip mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(_container);
        make.width.mas_equalTo(300);
        make.height.mas_equalTo(20);
    }];
    [buy mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf.effectBg).mas_offset(60);
        make.centerX.equalTo(weakSelf.effectBg);
        make.width.mas_equalTo(140);
        make.height.mas_equalTo(44);
    }];

    [_ADPlayView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_offset(0);
    }];
    [_hoem_recommend_playview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_offset(0);
    }];
//    [_hoem_recommend_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.edges.mas_offset(0);
//    }];
    [_container mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_offset(0);
        make.bottom.mas_offset(0);
    }];
    [_inputView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.right.mas_offset(-15);
        make.height.mas_offset(44);
        make.bottom.equalTo(self.container.mas_bottom).mas_offset(47);
    }];
    

    
    [_pauseIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(_container);
        make.width.height.mas_equalTo(100);
    }];
    
    //make constraintes
    [_playerStatusBar mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerX.equalTo(self);
        make.bottom.equalTo(self.inputView.mas_top).offset(-3);
        make.width.mas_equalTo(1.0f);
        make.height.mas_equalTo(2.0f);
    }];
    [_sliderView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.inputView.mas_top).offset(5);
        make.leading.trailing.mas_equalTo(0.0f);
        make.height.mas_equalTo(18.0f);
    }];
//    [_musicIcon mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self);
//        make.bottom.equalTo(self).offset(-10);
//        make.width.mas_equalTo(30);
//        make.height.mas_equalTo(25);
//    }];
//    
//    [_musicName mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.musicIcon.mas_right);
//        make.centerY.equalTo(self.musicIcon);
//        make.width.mas_equalTo(KScreen_W/2);
//        make.height.mas_equalTo(24);
//    }];
    [_desc mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(10);
        make.bottom.equalTo(_sliderView.mas_top).offset(-16);
        make.height.mas_equalTo (18);
        make.width.mas_lessThanOrEqualTo(KScreen_W/5*3);
    }];
    [_nickName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(10);
        make.bottom.equalTo(self.desc.mas_top).offset(-5);
        make.width.mas_lessThanOrEqualTo(KScreen_W/4*3 + 30);
    }];
    
    [_showMoneyView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(10);
        make.bottom.equalTo(self.nickName.mas_top).offset(-5);
        make.width.mas_lessThanOrEqualTo(KScreen_W/4*3 + 30);
        make.height.mas_offset(36);
    }];
    [_showMoneyBgImge mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.showMoneyView).offset(0);
    }];
    [_showMoneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.showMoneyView).offset(0);
        make.bottom.equalTo(self.showMoneyView).offset(0);
        make.left.equalTo(self.showMoneyView.mas_left).offset(15);
        make.right.equalTo(self.showMoneyView.mas_right).offset(-15);
    }];
    [_showMoneyButt mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.showMoneyView).offset(0);
    }];
    
//    [_musicAlum mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.bottom.equalTo(self.musicName);
//        make.right.equalTo(self).offset(-10);
//        make.width.height.mas_equalTo(50);
//    }];
    [_share mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_inputView.mas_top).offset(-58);
        make.right.equalTo(self).offset(-10);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(45);
    }];
    [_shareNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.share.mas_bottom);
        make.centerX.equalTo(self.share);
    }];
    [_hua mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.share.mas_top).offset(-25);
        make.right.equalTo(self).offset(-10);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(45);
    }];
    [_huaNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.hua.mas_bottom);
        make.centerX.equalTo(self.hua);
    }];
    
    [_comment mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.hua.mas_top).offset(-25);
        make.right.equalTo(self).offset(-10);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(45);
    }];
    [_commentNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.comment.mas_bottom);
        make.centerX.equalTo(self.comment);
    }];
    
    
    [_collection mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.comment.mas_top).offset(-25);
        make.right.equalTo(self).offset(-10);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(45);
    }];
    
    [_collectionNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.collection.mas_bottom);
        make.centerX.equalTo(self.collection);
    }];
    
    [_favorite mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.collection.mas_top).offset(-25);
        make.right.equalTo(self).offset(-10);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(45);
    }];
    
    [_favoriteNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.favorite.mas_bottom);
        make.centerX.equalTo(self.favorite);
    }];
    
    [_avatar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.favorite.mas_top).offset(-35);
        make.right.equalTo(self).offset(-10);
        make.width.height.mas_equalTo(avatarRadius*2);
    }];
    [_focus mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.avatar);
        make.centerY.equalTo(self.avatar.mas_bottom);
        make.width.height.mas_equalTo(24);
    }];
    _focus.myFollowFoucusBlock = ^(NSInteger index) {
        if(index == 0){
            [weakSelf followsUser];
        }
    };
    _favorite.myLikeFavoriteBlock = ^(NSInteger index) {
        if(index == 0){
            [weakSelf likeVideo:NO];
        }else if(index == 1){
            [weakSelf likeVideo:NO];
        }
    };
    
    _nickName.userInteractionEnabled = YES;
    [_nickName addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handToUserInfo)]];
    _avatar.userInteractionEnabled = YES;
    [_avatar addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handToUserInfo)]];

}
- (AVPlayer *)video_player{
    if(_video_player == nil){
        _video_playerItem = [AVPlayerItem playerItemWithURL:KUrlString(self.urlString)];
        _video_player = [AVPlayer playerWithPlayerItem:_video_playerItem];
        if([[UIDevice currentDevice] systemVersion].intValue>=10){
            //      增加下面这行可以解决iOS10兼容性问题了
            _video_player.automaticallyWaitsToMinimizeStalling = NO;
        }
        _video_playerLayer = [AVPlayerLayer playerLayerWithPlayer:_video_player];
        _video_playerLayer.frame = CGRectMake(0, 0, KScreen_W, self.cellHeight);
   
        if ([self.videoModel.width intValue] > [self.videoModel.height intValue]) {
            _video_playerLayer.videoGravity = AVLayerVideoGravityResizeAspect;
        }else{
            _video_playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
        }
        //放置播放器的视图
        [_hoem_recommend_playview.layer addSublayer:_video_playerLayer];
        [ _video_playerItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil];
        //监控是否可播放
        [_video_playerItem addObserver:self forKeyPath:@"playbackLikelyToKeepUp" options:NSKeyValueObservingOptionNew context:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinished) name:AVPlayerItemDidPlayToEndTimeNotification object:_video_player.currentItem];
     
    }
    return _video_player;
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:
(NSDictionary<NSString *,id> *)change context:(void *)context{
    if ([keyPath isEqualToString:@"status"]) {
        //取出status的新值
        AVPlayerItemStatus status = [change[NSKeyValueChangeNewKey]intValue];
        switch (status) {
            case AVPlayerItemStatusUnknown:
                [self startLoadingPlayItemAnim:YES];
                break;
            case AVPlayerItemStatusReadyToPlay:
                self.isEndLoading = YES;
                if(_isPlayerReady){
                    NSLog(@"视频播放回调开始");
                    [_video_player play];
                    
                }
                break;
            case AVPlayerItemStatusFailed:
                [self startLoadingPlayItemAnim:NO];
                [YBMsgPop showPop:@"加载失败"];
                break;
  
        }
    }else if ([keyPath isEqualToString:@"playbackLikelyToKeepUp"]){
        if (self.video_player.currentItem.playbackLikelyToKeepUp == YES) {
            if(_hoem_recommend_imageView.hidden == NO){
                _hoem_recommend_imageView.hidden = YES;
            }
            [self startLoadingPlayItemAnim:NO];
        }
    }
}
-(void)playbackFinished{
    [self.video_player seekToTime:CMTimeMake(0, 1)];
    [self.video_player play];
    if([QZUserInfoModel isLogin]){
        if(![[QZUserInfoModel share].playFishEndIdArr containsObject:self.videoModel.videoid]){
            [[QZUserInfoModel share].playFishEndIdArr addObject:self.videoModel.videoid];
            [[QZHongBaoView share] stopClick:NO];
        }
    }
}
#pragma mark 事件区域
- (void)handToUserInfo{
    if(self.videoModel.is_ADView){
        return;
    }
    if([QZUserInfoModel isLogin] == NO){
        [QZUserInfoModel presentLoginView];
        return;
    }
    if([self.videoModel.mid integerValue] == [[QZUserInfoModel share].mid integerValue]){
        //自己
        return;
    }
    [QZUserInfoModel otherMineControlView:[Tools currentActiveController] mineId:self.videoModel.mid videoId:self.videoModel.videoid];
}
- (void)followsUser{
    KWeakSelf
    KMutableDic(sendDic)
    [sendDic setObject:_videoModel.mid forKey:@"to_mid"];
    [YBNetBase userFollowUserRequest:sendDic target:[QZUserInfoModel share].mainVC successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
        if(code == 200){
            if([weakSelf.videoModel.isfollow intValue] == 1){
                weakSelf.videoModel.isfollow = @(0);
                [YBMsgPop showPop:@"已取消关注"];
            }else{
                weakSelf.videoModel.isfollow = @(1);
//                [YBMsgPop showPop:NSLocalizedString(@"已关注", nil)];
            }
        }else{
            [YBMsgPop showPop:msg];
        }
    }];
}
- (void)likeVideo:(BOOL)isDouble{
    KMutableDic(sendDic)
    KWeakSelf
    sendDic[@"videoid"] = self.videoModel.videoid;
    [YBNetBase videoLikeRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
        if(code == 200){
            
            weakSelf.videoModel.like_num = data[@"like_num"];
            weakSelf.videoModel.islike = data[@"islike"];
            [weakSelf.favoriteNum setText:[Tools NumberToShowString:[weakSelf.videoModel.like_num integerValue]]];
            [[QZDataUpdate share] updateLike:weakSelf.videoModel excludeTarget:[QZUserInfoModel share].mainVC];
            if(isDouble){
                weakSelf.favorite.favoriteAfter.hidden = NO;
                return;
            }
           
        }else{
            [YBMsgPop showPop:msg];
        }
    }];
}
-(void)prepareForReuse {
    [super prepareForReuse];
    _isPlayerReady = NO;
    [self.hoem_recommend_playview jp_pause];
    [_favorite resetView];
    [_focus resetView];
}

-(void)layoutSubviews {
    [super layoutSubviews];
    [CATransaction begin];
    [CATransaction setDisableActions:YES];
    _gradientLayer1.frame = CGRectMake(0, 0, self.frame.size.width, 200);
    _gradientLayer2.frame = CGRectMake(0, self.frame.size.height - 500, self.frame.size.width, 500);
    [CATransaction commit];
}

//SendTextDelegate delegate
- (void)onSendText:(NSString *)text {
    

}

//HoverTextViewDelegate delegate
-(void)hoverTextViewStateChange:(BOOL)isHover {
    _container.alpha = isHover ? 0.0f : 1.0f;
}
-(BOOL)gestureRecognizer:
    (UIGestureRecognizer*)gestureRecognizer shouldReceiveTouch:(nonnull UITouch *)touch{
   //若为UITableViewCellContentView（即点击了tableViewCell），则不截获Touch事件
    NSLog(@"%@", NSStringFromClass([touch.view class]));
    if([NSStringFromClass([touch.view class]) isEqualToString:@"YYLabel"]){
        self.isTouch = YES;
        return NO;
    }
   return YES;
  }
//gesture
- (void)handleGesture:(UITapGestureRecognizer *)sender {
    switch (sender.view.tag) {
        case kAwemeListLikeCollectionTag:{
            if(self.videoModel.is_ADView){
                return;
            }
            if([QZUserInfoModel isLogin] == NO){
                //没有登录
                [QZUserInfoModel presentLoginView];
                return;
            }
            KMutableDic(sendDic)
            sendDic[@"videoid"] = self.videoModel.videoid;
            KWeakSelf
            [YBNetBase videoCollectsRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
                if(code == 200){
                    if([weakSelf.videoModel.iscollect boolValue]){
                        weakSelf.collection.image = KImageNamed(@"home_video_collection_nor");
                        weakSelf.videoModel.iscollect = @(0);
                        weakSelf.videoModel.collect_num = @([weakSelf.videoModel.collect_num intValue]-1);
                        
                    }else{
                        weakSelf.collection.image = KImageNamed(@"home_video_collection_sel");
                        weakSelf.videoModel.iscollect = @(1);
                        weakSelf.videoModel.collect_num = @([weakSelf.videoModel.collect_num intValue]+1);
                    }
                    [weakSelf.collectionNum setText:[Tools NumberToShowString:[weakSelf.videoModel.collect_num integerValue]]];
                    [[QZDataUpdate share] updateCollection:weakSelf.videoModel excludeTarget:[QZUserInfoModel share].mainVC];
                }else{
                    [YBMsgPop showPop:msg];
                }
            }];
            break;
        }
        case kAwemeListLikeCommentTag: {
            if(self.videoModel.is_ADView){
                return;
            }
            if([QZUserInfoModel isLogin] == NO){
                //没有登录
                [QZUserInfoModel presentLoginView];
                return;
            }
            self.avatar.hidden = YES;
            self.focus.hidden = YES;
            self.favorite.hidden = YES;
            self.favoriteNum.hidden = YES;
            self.collection.hidden = YES;
            self.collectionNum.hidden = YES;
            self.comment.hidden = YES;
            self.commentNum.hidden = YES;
            self.share.hidden = YES;
            self.shareNum.hidden = YES;
            self.desc.hidden = YES;
            self.nickName.hidden = YES;
            self.sliderView.hidden = YES;
            _video_playerLayer.frame = CGRectMake(0, 0, KScreen_W, (KScreen_H-KTab_H)*0.35);
            _video_playerLayer.videoGravity = AVLayerVideoGravityResizeAspect;
            self.myPlayCommentBlock(0);
            break;
        }
        case kAwemeListLikeShareTag: {
            if(self.videoModel.is_ADView){
                return;
            }
            SharePopView *popView = [[SharePopView alloc] init];
            if([self.videoModel.mid integerValue] == [[QZUserInfoModel share].mid integerValue]){
                popView.bottomIconsName = @[@"ico_mine_more_share",@"ico_mine_more_download",@"ico_mine_more_delete"];
                popView.bottomTexts = @[@"分享",@"下载",@"删除"];
            }else{
                if([self.videoModel.download_permission intValue] == 1){
                    popView.bottomIconsName = @[@"ico_mine_more_share",@"ico_mine_more_jubao",@"ico_mine_more_notlike",@"ico_mine_more_download"];
                    popView.bottomTexts = @[@"分享",@"举报",@"没兴趣",@"下载"];
                }else{
                    popView.bottomIconsName = @[@"ico_mine_more_share",@"ico_mine_more_jubao",@"ico_mine_more_notlike"];
                    popView.bottomTexts = @[@"分享",@"举报",@"没兴趣"];
                }
                
            }
            popView.delegate = self;
            [popView show];
            break;
        }
        case kAwemeListLikeHuaTag: {
            if([QZUserInfoModel isLogin] == NO){
                //没有登录
                [QZUserInfoModel presentLoginView];
                return;
            }
            if(self.videoModel.is_ADView){
                return;
            }
            if([self.videoModel.is_flower intValue] == 1){
                [YBMsgPop showPop:@"已送花"];
                return;
            }
            if([self.videoModel.mid intValue] == [[QZUserInfoModel share].mid intValue]){
                [YBMsgPop showPop:@"不能送花给自己"];
                return;
            }
            KMutableDic(sendDic)
            sendDic[@"videoid"] = self.videoModel.videoid;
            KWeakSelf
            [YBNetBase videoFlowerRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
                if(code == 200){
                    weakSelf.hua.image = KImageNamed(@"home_video_hua_sel");
                    [UIView animateKeyframesWithDuration:1 delay:0 options:0 animations: ^{
                        weakSelf.hua.transform = CGAffineTransformMakeScale(0.1,0.1);
                        [UIView addKeyframeWithRelativeStartTime:0 relativeDuration:1 animations: ^{
                            weakSelf.hua.transform = CGAffineTransformMakeScale(1,1);
                        }];
                    } completion:nil];
                    
                    weakSelf.videoModel.is_flower = @(1);
                    weakSelf.huaNum.text = @"已送";
                    [[QZDataUpdate share] updateHua:weakSelf.videoModel excludeTarget:[Tools currentActiveController]];
                }else{
                    [YBMsgPop showPop:msg];
                }
            }];
            break;
        }
        default: {
            NSLog(@"%@",sender.view);
            if(self.isTouch){
                self.isTouch = NO;
                return;
            }
            //获取点击坐标，用于设置爱心显示位置
            CGPoint point = [sender locationInView:_container];
            //获取当前时间
            NSTimeInterval time = [[NSDate dateWithTimeIntervalSinceNow:0] timeIntervalSince1970];
            //判断当前点击时间与上次点击时间的时间间隔
            if(time - _lastTapTime > 0.25f) {
                //推迟0.25秒执行单击方法
                [self performSelector:@selector(singleTapAction) withObject:nil afterDelay:0.25f];
            }else {
                //取消执行单击方法
                [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(singleTapAction) object: nil];
                if(self.videoModel.is_ADView){
                    return;
                }
                if([QZUserInfoModel isLogin] == NO){
                    [QZUserInfoModel presentLoginView];
                    return;
                }
                if([self.videoModel.islike boolValue] == NO){
                    self.videoModel.islike = @(1);
                    [self likeVideo:YES];
                }
                //执行连击显示爱心的方法
                [self showLikeViewAnim:point oldPoint:_lastTapPoint];
            }
            //更新上一次点击位置
            _lastTapPoint = point;
            //更新上一次点击时间
            _lastTapTime =  time;
            break;
        }
    }
    
}
- (void)commentMoveStatus:(CGFloat)offset close:(BOOL)close{
    if(close){
        if((KScreen_H-KTab_H)*0.65/2 < offset){
            if(self.inputView.hidden){
                _video_playerLayer.frame = CGRectMake(0, 0, KScreen_W, (KScreen_H-KSafeAreaBottomHeight-50));
            }else{
                _video_playerLayer.frame = CGRectMake(0, 0, KScreen_W, KScreen_H-KTab_H);
            }
            
//            [_sliderView mas_updateConstraints:^(MASConstraintMaker *make) {
//                make.bottom.equalTo(self.inputView.mas_top).mas_equalTo(5);
//            }];
            self.avatar.hidden = NO;
            if([self.videoModel.isfollow boolValue] == NO){
                self.focus.hidden = NO;
            }
            self.favorite.hidden = NO;
            self.favoriteNum.hidden = NO;
            self.collection.hidden = NO;
            self.collectionNum.hidden = NO;
            self.comment.hidden = NO;
            self.commentNum.hidden = NO;
            self.share.hidden = NO;
            self.shareNum.hidden = NO;
            self.desc.hidden = NO;
            self.nickName.hidden = NO;
            self.sliderView.hidden = NO;
            if ([self.videoModel.width intValue] > [self.videoModel.height intValue]) {
                _video_playerLayer.videoGravity = AVLayerVideoGravityResizeAspect;
            }else{
                _video_playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
            }
        }else{
            _video_playerLayer.frame = CGRectMake(0, 0, KScreen_W, (KScreen_H-KTab_H)*0.35);
            _video_playerLayer.videoGravity = AVLayerVideoGravityResizeAspect;
        }
  
    }else{
        NSLog(@"%f",offset);
        _video_playerLayer.frame = CGRectMake(0, 0, KScreen_W, (KScreen_H-KTab_H)*0.35+offset);
    }
}
- (void)singleTapAction {
    if([_hoverTextView isFirstResponder]) {
        [_hoverTextView resignFirstResponder];
    }else {
        [self showPauseViewAnim:[_video_player rate]];
        if(_video_player.rate == 0) {
            [self video_playTap];
        }else {
            [self video_pauseTap];
        }
    }
}

//暂停播放动画
- (void)showPauseViewAnim:(CGFloat)rate {
   
    if(rate == 0) {
        [UIView animateWithDuration:0.25f
                         animations:^{
                             self.pauseIcon.alpha = 0.0f;
                         } completion:^(BOOL finished) {
                             [self.pauseIcon setHidden:YES];
                         }];
    }else {
        [_pauseIcon setHidden:NO];
        _pauseIcon.transform = CGAffineTransformMakeScale(1.8f, 1.8f);
        _pauseIcon.alpha = 1.0f;
        [UIView animateWithDuration:0.25f delay:0
                            options:UIViewAnimationOptionCurveEaseIn animations:^{
                                self.pauseIcon.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
                            } completion:^(BOOL finished) {
                            }];
    }
}

//连击爱心动画
- (void)showLikeViewAnim:(CGPoint)newPoint oldPoint:(CGPoint)oldPoint {
    UIImageView *likeImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"favAfter"]];
    CGFloat k = ((oldPoint.y - newPoint.y)/(oldPoint.x - newPoint.x));
    k = fabs(k) < 0.5 ? k : (k > 0 ? 0.5f : -0.5f);
    CGFloat angle = M_PI_4 * -k;
    likeImageView.frame = CGRectMake(newPoint.x, newPoint.y, 80, 80);
    likeImageView.transform = CGAffineTransformScale(CGAffineTransformMakeRotation(angle), 0.8f, 1.8f);
    [_container addSubview:likeImageView];
    [UIView animateWithDuration:0.2f
                          delay:0.0f
         usingSpringWithDamping:0.5f
          initialSpringVelocity:1.0f
                        options:UIViewAnimationOptionCurveEaseOut
                     animations:^{
                         likeImageView.transform = CGAffineTransformScale(CGAffineTransformMakeRotation(angle), 1.0f, 1.0f);
                     }
                     completion:^(BOOL finished) {
                         [UIView animateWithDuration:0.5f
                                               delay:0.5f
                                             options:UIViewAnimationOptionCurveEaseOut
                                          animations:^{
                                              likeImageView.transform = CGAffineTransformScale(CGAffineTransformMakeRotation(angle), 3.0f, 3.0f);
                                              likeImageView.alpha = 0.0f;
                                          }
                                          completion:^(BOOL finished) {
                                              [likeImageView removeFromSuperview];
                                          }];
                     }];
}

//加载动画
-(void)startLoadingPlayItemAnim:(BOOL)isStart {
    if (isStart) {
        self.sliderView.hidden = YES;
        _playerStatusBar.backgroundColor = [UIColor whiteColor];
        [_playerStatusBar setHidden:NO];
        [_playerStatusBar.layer removeAllAnimations];
        
        CAAnimationGroup *animationGroup = [[CAAnimationGroup alloc]init];
        animationGroup.duration = 0.5;
        animationGroup.beginTime = CACurrentMediaTime() + 0.5;
        animationGroup.repeatCount = MAXFLOAT;
        animationGroup.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        
        CABasicAnimation * scaleAnimation = [CABasicAnimation animation];
        scaleAnimation.keyPath = @"transform.scale.x";
        scaleAnimation.fromValue = @(1.0f);
        scaleAnimation.toValue = @(1.0f * KScreen_W);
        
        CABasicAnimation * alphaAnimation = [CABasicAnimation animation];
        alphaAnimation.keyPath = @"opacity";
        alphaAnimation.fromValue = @(1.0f);
        alphaAnimation.toValue = @(0.5f);
        [animationGroup setAnimations:@[scaleAnimation, alphaAnimation]];
        [self.playerStatusBar.layer addAnimation:animationGroup forKey:nil];
    } else {
        self.sliderView.hidden = NO;
        [self.playerStatusBar.layer removeAllAnimations];
        [self.playerStatusBar setHidden:YES];
    }
    
}

// AVPlayerUpdateDelegate
//-(void)onProgressUpdate:(CGFloat)current total:(CGFloat)total {
//    //播放进度更新
//
//    if (current == total) {
//
//        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//
//            [self.playerView replay];
//        });
//    }
//    self.sliderView.value = current / total;
//    if([self.videoModel.price intValue] > 0 && [self.videoModel.t_coin_num intValue] > 0 && [self.videoModel.mid intValue] != [[QZUserInfoModel share].mid intValue]){
//        //不是自己的付费视频并且没有购买过
//        if( [self.videoModel.try_second floatValue]-current < 0.5){
//            [self pause];
//            self.effectBg.hidden = NO;
//        }
//    }
//    if( [self.videoModel.durations floatValue]-current < 0.5){
//        [QZUserInfoModel addHisPlay:self.videoModel.videoid durations:[self.videoModel.durations floatValue] isPlayEnd:1];
//    }
////    NSLog(@"已播放时长:【 %.0f 】 已播放百分之:【 %.0f%@ 】  总时长：【%02d:%02d:%02d】",current,current / total * 100,@"%", (int)total/60/60,(int)total/60,(int)total%60);
//    if([QZUserInfoModel isLogin]){
//        if(self.isJiluIdReady && ![[QZUserInfoModel share].playFishEndIdArr containsObject:self.videoModel.videoid]){
//            if(total - current < 1){
//                [[QZUserInfoModel share].playFishEndIdArr addObject:self.videoModel.videoid];
//                [[QZHongBaoView share] stopClick:NO];
//            }
//        }
//    }
//}

-(void)onPlayItemStatusUpdate:(AVPlayerItemStatus)status {
    switch (status) {
        case AVPlayerItemStatusUnknown:
            [self startLoadingPlayItemAnim:YES];
            break;
        case AVPlayerItemStatusReadyToPlay:
            [self startLoadingPlayItemAnim:NO];
//            [_musicAlum startAnimation:0];
            
            if(_onPlayerReady) {
                _onPlayerReady(self.indexRow);
            }
            break;
        case AVPlayerItemStatusFailed:
            [self startLoadingPlayItemAnim:NO];
            [YBMsgPop showPop:@"加载失败"];
            break;
        default:
            break;
    }
}

// update method
//- (void)initData:(QZVideoModel *)data{
- (void)setVideoModel:(QZVideoModel *)videoModel{
    _videoModel = videoModel;
    self.effectBg.hidden = YES;
    if(videoModel.is_ADView){
        self.urlString = @"";
        [QZUserInfoModel share].adPlayId = videoModel.expressViewId;
        _ADPlayView.hidden = NO;
        _avatar.image = KImageNamed(@"home_AD_image");
        self.focus.hidden = NO;
        _favorite.favoriteAfter.hidden = YES;
        self.favorite.isADView = YES;
        self.focus.isADView = YES;
        self.collection.image = KImageNamed(@"home_video_collection_nor");
        self.showMoneyView.hidden = YES;
        [_favoriteNum setText:@"0"];
        [_collectionNum setText:@"0"];
        [_commentNum setText:@"0"];
        [_shareNum setText:@"更多"];
        [_huaNum setText:@"送花"];
        _hua.image = KImageNamed(@"home_video_hua_nor");
        NSMutableAttributedString * moreAttr = [[NSMutableAttributedString alloc] initWithString:@"广告" attributes:@{NSForegroundColorAttributeName : ColorHex_Alpha(@"FFFFFF", 0.77), NSFontAttributeName : Font(14)}];
        _desc.numberOfLines = 2;
        videoModel.introHeight = [moreAttr boundingRectWithSize:CGSizeMake(KScreen_W/5*3, _desc.font.lineHeight*2) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading context:nil].size.height+2;
        [self updateVideoTalks:moreAttr];
        _desc.attributedText = moreAttr;
        
        UIView *subView = (UIView *)[_ADPlayView viewWithTag:1000];
        if ([subView superview]) {
            [subView removeFromSuperview];
        }
        if(videoModel.expressView != nil){
            BUNativeExpressAdView *view = videoModel.expressView;
            view.tag = 1000;
            [_ADPlayView addSubview:view];
        }
    }else{
        self.sliderView.value = 0;
        if(self.videoModel.video_play_url.length == 0){
            [self.hoem_recommend_imageView sd_setImageWithURL:KUrlString(self.videoModel.image)];
            self.hoem_recommend_imageView.hidden = NO;
            self.isEndLoading = NO;
            [self videoGetPlayUrlRequest];
        }else{
            if(![self.urlString isEqualToString:videoModel.video_urlModel.download_url]){
                [self.hoem_recommend_imageView sd_setImageWithURL:KUrlString(self.videoModel.image)];
                self.hoem_recommend_imageView.hidden = NO;
                self.urlString = videoModel.video_urlModel.download_url;
                self.isEndLoading = NO;
                [self videoPlayItemStart:NO];
            }else{
                self.isEndLoading = YES;
            }
          
        }
        if([videoModel.width floatValue] >= [videoModel.height floatValue]){
            self.hoem_recommend_imageView.contentMode = UIViewContentModeScaleAspectFit;
        }else{
            self.hoem_recommend_imageView.contentMode = UIViewContentModeScaleAspectFill;
        }
        if(videoModel.is_rank){
            _showMoneyView.hidden = NO;
            _showMoneyLabel.text = [NSString stringWithFormat:@"视频创作收益到账：%@",videoModel.income];
            CGFloat w = [Tools sizeForText:_showMoneyLabel.text withFont:FontMedium(14) withSize:CGSizeMake(MAXFLOAT, 36)].width+43;
            [_showMoneyView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.width.mas_equalTo(w);
            }];
            _showMoneyBgImge.image = [Tools changeImagSize:KImageNamed(@"ico_play_income") toSize:CGSizeMake(w, 36)];
        }else{
            _showMoneyView.hidden = YES;
        }
//        self.urlString = @"http://c.tikevideos.ltd/tikevideos/1715422607163875606.mp4?auth_key=1720764891-2836-0-d76615871f337392dd3aa7bd426767fd";
    
        _ADPlayView.hidden = YES;
        self.favorite.isADView = NO;
        self.focus.isADView = NO;
        
        _nickName.text = [NSString stringWithFormat:@"@ %@",videoModel.nickname];
        [_avatar sd_setImageWithURL:KUrlString(videoModel.face) placeholderImage:KImageNamed(@"ic_head_defuls") completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
            if(error){
                
            }
        }];
        if([videoModel.isfollow boolValue] || [videoModel.mid intValue] == [[QZUserInfoModel share].mid intValue]){
            _focus.hidden = YES;
        }else{
            _focus.hidden = NO;
        }
        NSMutableAttributedString * moreAttr = [[NSMutableAttributedString alloc] initWithString:videoModel.introduce attributes:@{NSForegroundColorAttributeName : ColorHex_Alpha(@"FFFFFF", 0.77), NSFontAttributeName : Font(14)}];
        KWeakSelf
        if(videoModel.isOpenIntro){
            NSMutableAttributedString * closeAttr = [[NSMutableAttributedString alloc] initWithString:@".... 收起" attributes:@{NSForegroundColorAttributeName : [UIColor whiteColor], NSFontAttributeName : FontMedium(14)}];
            [closeAttr setTextHighlightRange:NSMakeRange(0, closeAttr.length) color:[UIColor whiteColor] backgroundColor:UIColor.clearColor tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
                //点击
                videoModel.isOpenIntro = NO;
                NSMutableAttributedString * moreAttr = [[NSMutableAttributedString alloc] initWithString:videoModel.introduce attributes:@{NSForegroundColorAttributeName : [UIColor whiteColor], NSFontAttributeName : Font(14)}];
                weakSelf.desc.numberOfLines = 2;
                videoModel.introHeight = [moreAttr boundingRectWithSize:CGSizeMake(KScreen_W/5*3, weakSelf.desc.font.lineHeight*2) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading context:nil].size.height+2;
                [weakSelf updateVideoTalks:moreAttr];
                weakSelf.desc.attributedText = moreAttr;
                [weakSelf.desc mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.height.mas_equalTo (weakSelf.videoModel.introHeight);
                }];
            }];
            [moreAttr appendAttributedString:closeAttr];
            
            _desc.numberOfLines = 0;
            videoModel.introHeight = [moreAttr boundingRectWithSize:CGSizeMake(KScreen_W/5*3, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading context:nil].size.height;
      
        }else{
            _desc.numberOfLines = 2;
            videoModel.introHeight = [moreAttr boundingRectWithSize:CGSizeMake(KScreen_W/5*3, _desc.font.lineHeight*2) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading context:nil].size.height+2;
        }
        [self updateVideoTalks:moreAttr];
        _desc.attributedText = moreAttr;
        [_desc mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo (videoModel.introHeight);
        }];
        
//        [_desc setText:videoModel.introduce];
    //    [_musicName setText:@"天下无双"];
        
        [_favoriteNum setText:[Tools NumberToShowString:[videoModel.like_num integerValue]]];
        if([videoModel.islike boolValue]){
            _favorite.favoriteAfter.hidden = NO;
            _favorite.favoriteAfter.transform = CGAffineTransformScale(CGAffineTransformMakeRotation(0), 1.0f, 1.0f);
        }else{
            _favorite.favoriteAfter.hidden = YES;
        }
        if([videoModel.iscollect boolValue]){
            self.collection.image = KImageNamed(@"home_video_collection_sel");
        }else{
            self.collection.image = KImageNamed(@"home_video_collection_nor");
        }
        if([videoModel.is_flower intValue] == 1){
            [_huaNum setText:@"已送"];
            _hua.image = KImageNamed(@"home_video_hua_sel");
        }else{
            [_huaNum setText:@"送花"];
            _hua.image = KImageNamed(@"home_video_hua_nor");
        }
        [_collectionNum setText:[Tools NumberToShowString:[videoModel.collect_num integerValue]]];
        [_commentNum setText:[Tools NumberToShowString:[videoModel.comment_num integerValue]]];
        [_shareNum setText:@"更多"];
        [self layoutIfNeeded];
        NSLog(@"%f",CGRectGetMaxY(_nickName.frame));
    }
}
-(void)videoGetPlayUrlRequest{
    KMutableDic(sendDic)
    KWeakSelf
    if(![self.videoModel.video_url isKindOfClass:[NSDictionary class]] || self.videoModel.video_url == nil || [self.videoModel.video_url allKeys].count == 0){
        return;
    }
    sendDic[@"vid"] = self.videoModel.video_url[@"vid"];
    [YBNetBase getStreamVideoRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
        if(code == 200){
            weakSelf.videoModel.video_urlModel = [[QZVideoVideoUrlModel alloc]init];
            weakSelf.videoModel.video_urlModel.video = [[QZVideoVideoModel alloc]init];
            weakSelf.videoModel.video_urlModel.stream = [[NSMutableArray alloc]init];
            weakSelf.videoModel.video_urlModel.download_url = data[@"download_url"];
            [weakSelf.videoModel.video_urlModel.video setValuesForKeysWithDictionary:data[@"video"]];
            for (NSDictionary * dic in data[@"stream"]) {
                QZVideostreamModel * model = [[QZVideostreamModel alloc]init];
                [model setValuesForKeysWithDictionary:dic];
                [weakSelf.videoModel.video_urlModel.stream addObject:model];
            }
            weakSelf.videoModel.video_play_url = weakSelf.videoModel.video_urlModel.download_url ;
            weakSelf.urlString = weakSelf.videoModel.video_play_url;
 
            if(weakSelf.videoModel.is_request_down){
                weakSelf.videoModel.is_request_down = NO;
                [weakSelf videoPlayItemStart:YES];
            }else{
                [weakSelf videoPlayItemStart:NO];
            }
            
        }else
        {
            [YBMsgPop showPop:msg];
        }
    }];
}
- (void)videoPlayItemStart:(BOOL)isPlay{
    if(_video_playerLayer == nil){
     
        
    }else{
        if ([self.videoModel.width intValue] > [self.videoModel.height intValue]) {
            _video_playerLayer.videoGravity = AVLayerVideoGravityResizeAspect;
        }else{
            _video_playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
        }
        //移除监听（观察者）
        [_video_playerItem removeObserver:self forKeyPath:@"status"];
        //监控是否可播放
        [_video_playerItem removeObserver:self forKeyPath:@"playbackLikelyToKeepUp"];
        [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
        _video_playerItem = [AVPlayerItem playerItemWithURL:KUrlString(self.urlString)];
        [_video_player replaceCurrentItemWithPlayerItem:_video_playerItem];
        [ _video_playerItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil];
        //监控是否可播放
        [_video_playerItem addObserver:self forKeyPath:@"playbackLikelyToKeepUp" options:NSKeyValueObservingOptionNew context:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinished) name:AVPlayerItemDidPlayToEndTimeNotification object:_video_player.currentItem];
    }
    if(isPlay){
        [self video_playTap];
    }
}
- (void)updateVideoTalks:(NSMutableAttributedString *)moreAtter  {
    if (self.videoModel.labels && [self.videoModel.labels isKindOfClass:[NSArray class]] && self.videoModel.labels.count > 0) {
        //这里临时获取 string
        if (moreAtter.string.length > 0) {
            NSString * intro_str = moreAtter.string;
            KWeakSelf
            for (NSString *label in self.videoModel.labels) {
                NSString *r_label = [@"#" stringByAppendingString:label];//[[@"#"stringByAppendingString:label] stringByAppendingString:@" "];
//                if (_content) {
                NSRegularExpression *regex = [[NSRegularExpression alloc] initWithPattern:r_label options:NSRegularExpressionCaseInsensitive | NSRegularExpressionDotMatchesLineSeparators error:nil];
                NSArray *theArray = [regex matchesInString:intro_str options:NSMatchingReportProgress range:NSMakeRange(0, intro_str.length)];
                for ( NSTextCheckingResult *ele in theArray) {
                    //                            NSString *theLastString = [string substringWithRange:[ele rangeAtIndex:0]];
                    //                            NSLog(@"theLastString = %@",theLastString);
                    NSRange range = ele.range;//[_content rangeOfString:r_label];
                    if (range.length > 0 && range.location + range.length <= intro_str.length) {
                        [moreAtter addAttributes:@{NSForegroundColorAttributeName : UIColor.whiteColor, NSFontAttributeName : FontMedium(14)} range:range];
                        [moreAtter setTextHighlightRange:range color:UIColor.whiteColor backgroundColor:UIColor.clearColor tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range1, CGRect rect) {
                            if(weakSelf.myPlayCommentBlock){
                                NSString * str = [text.string substringWithRange:range1];
                                weakSelf.myPlayPopularBlock([str stringByReplacingOccurrencesOfString:@"#" withString:@""]);
                            }
                        }];
                    }
                }
            }
        }
    }
}

- (void)uploadShowPlayModel:(QZVideoModel *)model{
    self.videoModel = model;
    self.favorite.isADView = NO;
    self.focus.isADView = NO;
    
    if([model.isfollow boolValue]){
        _focus.hidden = YES;
    }else{
        _focus.hidden = NO;
    }
    [_desc setText:model.introduce];
//    [_musicName setText:@"天下无双"];
    
    [_favoriteNum setText:[Tools NumberToShowString:[model.like_num integerValue]]];
    if([model.islike boolValue]){
        _favorite.favoriteAfter.hidden = NO;
    }else{
        _favorite.favoriteAfter.hidden = YES;
    }
    if([model.iscollect boolValue]){
        self.collection.image = KImageNamed(@"home_video_collection_sel");
    }else{
        self.collection.image = KImageNamed(@"home_video_collection_nor");
    }
    [_collectionNum setText:[Tools NumberToShowString:[model.collect_num integerValue]]];
    [_commentNum setText:[Tools NumberToShowString:[model.comment_num integerValue]]];
}
- (void)video_playTap {
    if(self.urlString.length != 0){
        self.avTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(slidertimer) userInfo:nil repeats:YES];
        _isPlayerReady = YES;
        if(self.isEndLoading){
            NSLog(@"视频播放正常开始");
            [_video_player play];
            _hoem_recommend_imageView.hidden = YES;
        }
        
    
        [_pauseIcon setHidden:YES];
        if([self.videoModel.mid intValue] == [[QZUserInfoModel share].mid intValue]){
            [QZHongBaoView share].hidden = YES;
            [[QZHongBaoView share] stopClick:NO];
        }else if([QZUserInfoModel isLogin] && ![[QZUserInfoModel share].playFishEndIdArr containsObject:self.videoModel.videoid]){
            [[QZHongBaoView share] stopClick:YES];
        }
    }
}
- (void)slidertimer{
    self.sliderView.value = CMTimeGetSeconds(self.video_player.currentItem.currentTime) / CMTimeGetSeconds(self.video_player.currentItem.duration);
    
}
- (void)video_pauseTap {
    if(self.urlString.length != 0){
        [self.avTimer invalidate];
        _isPlayerReady = NO;
        [_video_player pause];
        [QZUserInfoModel addHisPlay:self.videoModel.videoid durations:[self.videoModel.durations floatValue]*self.sliderView.value isPlayEnd:0];
        if([QZUserInfoModel isLogin] && [QZHongBaoView share].hongbaoStatus){
            [[QZHongBaoView share] stopClick:NO];
        }
    }
}

- (void)pauseAdShow {
    if(self.urlString.length != 0){
        [_video_player pause];
        [QZUserInfoModel addHisPlay:self.videoModel.videoid durations:[self.videoModel.durations floatValue]*self.sliderView.value isPlayEnd:0];
    }
}
- (void)commentShowView{
    self.cellHeight = self.cellHeight-50-KSafeAreaBottomHeight;
    self.hoem_recommend_imageView.frame = CGRectMake(0, 0, KScreen_W, self.cellHeight);
    [_inputView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.container.mas_bottom).mas_offset(-3-KSafeAreaBottomHeight);
    }];
    [_hoem_recommend_playview mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self).mas_offset(-50-KSafeAreaBottomHeight);
    }];
    self.inputView.hidden = NO;
}
- (void)commentTap{
    self.avatar.hidden = YES;
    self.focus.hidden = YES;
    self.favorite.hidden = YES;
    self.favoriteNum.hidden = YES;
    self.collection.hidden = YES;
    self.collectionNum.hidden = YES;
    self.comment.hidden = YES;
    self.commentNum.hidden = YES;
    self.share.hidden = YES;
    self.shareNum.hidden = YES;
    self.desc.hidden = YES;
    self.nickName.hidden = YES;
    self.sliderView.hidden = YES;
    _video_playerLayer.frame = CGRectMake(0, 0, KScreen_W, (KScreen_H-KTab_H)*0.35);
    _video_playerLayer.videoGravity = AVLayerVideoGravityResizeAspect;
    self.myPlayCommentBlock(0);
}
#pragma mark - SharePopViewDelegate
- (void)actionClickedAtIndex:(NSInteger)index type:(NSString *)type
{
    if(self.videoModel.is_ADView){
        return;
    }
    if([QZUserInfoModel isLogin] == NO){
        [QZUserInfoModel presentLoginView];
        return;
    }
    if([type isEqualToString:@"分享"]){
        //分享
        [Tools iosSystemShare:@[[NSURL URLWithString:SHAREURL]] sourceView:self success:^{
            [YBMsgPop showPop:@"分享成功"];
        } fail:^{
            [YBMsgPop showPop:@"分享失败"];
        }];
    }else if ([type isEqualToString:@"举报"]){
        //举报
        [QZHongBaoView share].hidden = NO;
        [[QZHongBaoView share] stopClick:NO];
        DJJubaoVC * jubao = [[DJJubaoVC alloc]init];
        jubao.type = YVVideoReport;
        jubao.reportId = self.videoModel.videoid;
        [[Tools currentActiveController].navigationController pushViewController:jubao animated:YES];
    }else if ([type isEqualToString:@"下载"]){
        //下载
        PHAuthorizationStatus status ;
        if (@available(iOS 14, *)) {
             status = [PHPhotoLibrary authorizationStatusForAccessLevel:PHAccessLevelAddOnly];
        } else {
            // Fallback on earlier versions
            status = PHPhotoLibrary.authorizationStatus;
        }
        if (status == PHAuthorizationStatusRestricted|| status == PHAuthorizationStatusDenied){
            //跳转到设置界面
            NSString *title = nil;
            if (@available(iOS 14, *)) {
                title = @"相册写入权限关闭";
            } else {
                title = @"相册权限关闭";
            }
            [[BSystemAlert shared] showAlertWithTitle:@"温馨提示" message:title userData:nil cancelTitle:@"取消" actions:@[@"前往设置"] actionBlock:^(id  _Nonnull userData, NSString * _Nonnull actionTitle) {
                if ([actionTitle isEqualToString:@"前往设置"]) {
                    NSString *url = UIApplicationOpenSettingsURLString;
                    if([[UIApplication sharedApplication] canOpenURL:KUrlString(url)]) {
                        [[UIApplication sharedApplication] openURL:KUrlString(url) options:@{} completionHandler:^(BOOL success) {
                        }];
                    }
                }
            }];
        }else if (status == PHAuthorizationStatusNotDetermined) {
            KWeakSelf
            if (@available(iOS 14, *)) {
                [PHPhotoLibrary requestAuthorizationForAccessLevel:PHAccessLevelAddOnly handler:^(PHAuthorizationStatus status) {
                    if (status == PHAuthorizationStatusAuthorized) {
                        [weakSelf saveVideo];
                    } else if (status == PHAuthorizationStatusRestricted|| status == PHAuthorizationStatusDenied) {
                        [YBMsgPop showPop:@"视频保存失败"];
                    }
                }];
            } else {
                // Fallback on earlier versions
                [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
                    dispatch_async(dispatch_get_main_queue(), ^{
                        if (status == PHAuthorizationStatusAuthorized) {
                            [weakSelf saveVideo];
                        } else if (status == PHAuthorizationStatusRestricted|| status == PHAuthorizationStatusDenied) {
                            [YBMsgPop showPop:@"视频保存失败"];
                        }
                    });
                }];
            }
        }else{
            [self saveVideo];
        }
    }else if ([type isEqualToString:@"没兴趣"]){
        KMutableDic(sendDic);
        sendDic[@"videoid"] = self.videoModel.videoid;
        sendDic[@"reason"] = @"其它";
        sendDic[@"other_reason"] = @"其它原因";
        KWeakSelf
        [YBNetBase videoSaveLoseInterestRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
            if(code == 200){
                [[QZDataUpdate share] updateNoLike:weakSelf.videoModel.videoid excludeTarget:nil];
                [YBMsgPop showPop:@"视频不感兴趣设置成功"];
            }else{
                [YBMsgPop showPop:msg];
            }
        }];
    }else if ([type isEqualToString:@"删除"]){
        //删除
        KMutableDic(sendDic);
        sendDic[@"videoid"] = self.videoModel.videoid;
        KWeakSelf
        [YBNetBase videoDelVideoRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
            if(code == 200){
                [[QZDataUpdate share] delVideo:weakSelf.videoModel excludeTarget:nil];
                [YBMsgPop showPop:@"删除成功"];
            }else{
                [YBMsgPop showPop:msg];
            }
        }];
    }else if ([type isEqualToString:@"拉黑"]){
        KMutableDic(sendDic)
        [sendDic setObject:self.videoModel.mid forKey:@"tomid"];
        [YBNetBase userBlackUserRequest:sendDic userid:self.videoModel.mid target:[Tools currentActiveController] successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
            if(code == 200){
                [YBMsgPop showPop:@"已拉黑"];
            }else{
                [YBMsgPop showPop:msg];
            }
        }];
    }
}
- (void)saveVideo{
    NSString * savePath = self.urlString;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    //实际上获得的是：UTC时间，协调世界时，亚州的时间与UTC的时差均为+8
    NSDate * nowdate = [NSDate date];
    //zone为当前时区信息  在我的程序中打印的是@"Asia/Shanghai"
    NSTimeZone *zone = [NSTimeZone systemTimeZone];
    //28800 //所在地区时间与协调世界时差距
    NSInteger interval = [zone secondsFromGMTForDate:nowdate];
    NSDate *localeDate = [nowdate dateByAddingTimeInterval: interval];
    NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyyMMddhhmmss"];
    NSString * dateStr = [formatter stringFromDate:localeDate];
    NSString *fullPath = [NSString stringWithFormat:@"%@/%@.mp4", documentsDirectory, dateStr];
    NSURLRequest *request = [NSURLRequest requestWithURL:KUrlString(self.urlString)];
    KWeakSelf
    NSURLSessionDownloadTask *task = [[AFHTTPSessionManager manager] downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull downloadProgress) {

    } destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) {
        return [NSURL fileURLWithPath:fullPath];
    } completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) {
        dispatch_async(dispatch_get_main_queue(), ^{
            if (error != nil) {
                [YBMsgPop showPop:@"视频下载失败"];
                return;
            }
        });
        [weakSelf canSave:fullPath];
    }];
    [task resume];
    
}
- (void)canSave:(NSString *)savePath{
    if(savePath) {
        NSURL * sourt = [NSURL fileURLWithPath:savePath];
        NSString * path = [sourt path];
        BOOL compatible = UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(path);
        if(compatible){
            //保存相册核心代码
            UISaveVideoAtPathToSavedPhotosAlbum(path,self,@selector(savedVideoPhotoImage:didFinishSavingWithError:contextInfo:),nil);
        }
    }
}
- (void)savedVideoPhotoImage:(UIImage*)image didFinishSavingWithError: (NSError*)error contextInfo: (void*)contextInfo{
    if(error == nil){
        [YBMsgPop showPop:@"视频保存相册成功"];
    }else{
        [YBMsgPop showPop:@"视频保存相册失败"];
    }
}
-(void)buyVideoTap{
    KMutableDic(sendDic)
    sendDic[@"vid"] = self.videoModel.videoid;
    [SVProgressHUDTool showWithStatus:nil];
    KWeakSelf
    [YBNetBase buyVideoWalletListdoSignInRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
        [SVProgressHUDTool dismiss];
        if(code == 200){
            weakSelf.effectBg.hidden = YES;
            weakSelf.videoModel.t_coin_num = @(0);
            [weakSelf video_playTap];
            [YBMsgPop showPop:@"购买成功"];
        }else if (code == 1002){
            DJMYBIVC * bi = [[DJMYBIVC alloc]init];
            bi.modalPresentationStyle = UIModalPresentationFullScreen;
            bi.isPre= YES;
            [[Tools currentActiveController] presentViewController:bi animated:YES completion:^{
                [YBMsgPop showPop:@"金币不足,请充值"];
            }];
        }else{
            [YBMsgPop showPop:msg];
        }
    }];
}
// 滑块滑动开始
- (void)sliderTouchBegan:(float)value{
    self.desc.hidden = YES;
    self.avatar.hidden = YES;
    self.nickName.hidden = YES;
    self.sliderView.sliderHeight = 10;
}
// 滑块滑动中
- (void)sliderValueChanged:(float)value{
    
}
// 滑块滑动结束
- (void)sliderTouchEnded:(float)value{
    self.desc.hidden = NO;
    self.avatar.hidden = NO;
    self.nickName.hidden = NO;
    self.sliderView.sliderHeight = 2;
    CMTime seekTime = CMTimeMakeWithSeconds([self.videoModel.durations floatValue], 1.0);
    [self.video_playerItem seekToTime:seekTime completionHandler:^(BOOL finished) {
        
    }];
}
// 滑杆点击
- (void)sliderTapped:(float)value{
    
}

/*第一版本*/
//- (instancetype)initWithFrame:(CGRect)frame
//{
//    self = [super initWithFrame:frame];
//    if (self) {
//        CGSize size_now = frame.size;
//
//        self.hoem_recommend_playview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, size_now.width, size_now.height-10)];
//        [self addSubview:self.hoem_recommend_playview];
//
//        self.hoem_recommend_imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
//        self.hoem_recommend_imageView.contentMode = UIViewContentModeScaleAspectFill;
//        self.hoem_recommend_imageView.clipsToBounds = YES;
//        [self addSubview:self.hoem_recommend_imageView];
//
//
//
//        UIView * colorView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, size_now.width, size_now.height)];
//        CAGradientLayer * gradientLayer = [CAGradientLayer layer];
//        gradientLayer.frame = CGRectMake(0, size_now.height/2, size_now.width, size_now.height/2);
//        gradientLayer.colors = @[(__bridge id)COLOR_ALPH(0, 0, 0, 0).CGColor,(__bridge id)COLOR_ALPH(0, 0, 0, 0.5).CGColor];
//        gradientLayer.startPoint = CGPointMake(0, 0);
//        gradientLayer.endPoint = CGPointMake(0, 1);
//        gradientLayer.locations = @[@0,@1];
//        [colorView.layer addSublayer:gradientLayer];
//        [self addSubview:colorView];
//
//        UIView * colorView1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, size_now.width, size_now.height)];
//        CAGradientLayer * gradientLayer1 = [CAGradientLayer layer];
//        gradientLayer1.frame = CGRectMake(0, 0, size_now.width, size_now.height/2);
//        gradientLayer1.colors = @[(__bridge id)COLOR_ALPH(0, 0, 0, 0.5).CGColor,(__bridge id)COLOR_ALPH(0, 0, 0, 0).CGColor];
//        gradientLayer1.startPoint = CGPointMake(0, 0);
//        gradientLayer1.endPoint = CGPointMake(0, 1);
//        gradientLayer1.locations = @[@0,@1];
//        [colorView1.layer addSublayer:gradientLayer1];
//        [self addSubview:colorView1];
//
//        self.hoem_recommend_playbutton = [[QzVideoPlayButtonView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
//        self.hoem_recommend_playbutton.hidden = YES;
//        [self addSubview:self.hoem_recommend_playbutton];
//
//
//        self.slider = [QZVideoPlaySliderView new];
//        [self addSubview:self.slider];
//        self.hoem_recommend_playview.jp_progressView = self.slider;
//    }
//    return self;
//}
//- (void)showPlayModel:(QZVideoModel *)model{
//
//}
//- (void)resumePlay:(NSString *)videoUrl{
//    BVideoCacheResult cacheResult = [[BVideoCacheTool tool] getVideoPathWithWebUrl:videoUrl];
////    if((self.playCacheResult.isLocalPath && !cacheResult.isLocalPath)){
//        [self playVideoWithUrl:videoUrl];//播放网络
////    }
////    else
////    {
////        [self.hoem_recommend_playview jp_resume];//播放缓存
////    }
//}
//- (void)stopPlayWithUrl:(NSString *)videoUrl{
//    //第一种：
//    [self.hoem_recommend_playview jp_stopPlay];
//}
//- (void)playVideoWithUrl:(NSString *)videoUrl{
//    /**第一种播放方式JPvideoPlay**/
//    NSLog(@"&&&&&&&&&&&11111传入原始播放地址:%@",videoUrl);
//    if (_isPause) {
//        return;
//    }
//    self.isOnePlayFinish = YES;
//    BVideoCacheResult cacheResult = [[BVideoCacheTool tool] getVideoPathWithWebUrl:videoUrl];
//    self.playCacheResult = cacheResult;
//    NSLog(@"&&&&&&&&&&&2222传入播放地址:%@",cacheResult.path);
//    NSURL *url = [NSURL URLWithString:cacheResult.path];
//    if(cacheResult.isLocalPath){
//        url = [NSURL fileURLWithPath:cacheResult.path];
//    }
//
//    [self.hoem_recommend_playview jp_playVideoMuteWithURL:url bufferingIndicator:nil progressView:nil configuration:^(UIView * _Nonnull view, JPVideoPlayerModel * _Nonnull playerModel) {
//        UIImage * image = self.hoem_recommend_imageView.image;
//        NSLog(@"%f===%f",self.hoem_recommend_imageView.image.size.width,self.hoem_recommend_imageView.image.size.height);
//        if (image) {
//            if (image.size.width>=image.size.height) {
//                playerModel.playerLayer.videoGravity = AVLayerVideoGravityResizeAspect;
//            }else{
//                playerModel.playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
//            }
//        }else{
//            playerModel.playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
//        }
//    }];
//    self.hoem_recommend_playview.jp_videoPlayerDelegate = self;
//}
@end
